'''
修改了数据集分割, 训练、验证比例为8:2, 保存验证集图像
'''
import os
import os.path

IMG_EXTENSIONS = [
    '.jpg', '.JPG', '.jpeg', '.JPEG',
    '.png', '.PNG', '.ppm', '.PPM', '.bmp', '.BMP',
]

def is_image_file(filename):
    return any(filename.endswith(extension) for extension in IMG_EXTENSIONS)

def dataloader(filepath):
    left_fold = 'image_2/'
    right_fold = 'image_3/'
    disp_occ_fold = 'disp_occ_0/'

    image = [img for img in os.listdir(filepath+left_fold) if img.find('_10') > -1]

    img_num = len(image)
    val_rate = 0.2 # 验证集占比

    val = image[int(img_num * (1 - val_rate)):]

    left_test = [filepath+left_fold+img for img in val]
    right_test = [filepath+right_fold+img for img in val]
    disp_test = [filepath+disp_occ_fold+img for img in val]

    return left_test, right_test
